
#ifndef STOPWATCH_MODEL_H_INCLUDED
#define STOPWATCH_MODEL_H_INCLUDED

#include <e32std.h>
#include <e32base.h>

#include "StopwatchModelObserver.h"

class RFs;
class RReadStream;
class RWriteStream;

class CStopwatchModel : public CBase
{
public:
  ~CStopwatchModel();
  static CStopwatchModel* NewL(MStopwatchModelObserver& aObserver);
  static CStopwatchModel* NewLC(MStopwatchModelObserver& aObserver);

  void Start();
  void Stop();
  void Reset();//Reset the time to 0 and clear all snapshots, but continue running (if was previously started).
  void MakeSnapshotL();
//  void ResetValue(const TTimeIntervalMicroSeconds& aNewValue);

  TTimeIntervalMicroSeconds Value() const;
  TArray<TSnapshot> Snapshots() const;
  TBool IsRunning() const;


  void LoadL(RFs& aFs, const TDesC& aFileName);
  void LoadL(RReadStream& aIn);
  void SaveL(RFs& aFs, const TDesC& aFileName);
  void SaveL(RWriteStream& aOut);

private:
  CStopwatchModel(MStopwatchModelObserver& aObserver);
  void ConstructL();

  TBool iIsStarted;
  TTime iStartTime;
  TTimeIntervalMicroSeconds iTimeDiff;
  RArray<TSnapshot> iSnapshots;

  MStopwatchModelObserver& iObserver;
};

#endif // STOPWATCH_MODEL_H_INCLUDED
